<template>
	<view class="box">
		<view class="cnter">
			<view class="box1">
				<text>头像</text>
				<view class="right">
					<u-upload  :action="action"  @on-Success="onSuccess"
						 :header="token" max-count=1 width="150rpx" height="150rpx" 
						upload-text="请选则图片"></u-upload>
					<!-- <image :src="{{usersins.userPicture}}" mode="widthFix"></image> -->
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="box1">
				<text>用户名称</text>
				<view class="right">
					<text>{{usersins.userName}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="box1">
				<text>积分</text>
				<view class="right">
					<text>{{usersins.userIntegral}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="box1">
				<text>信用分</text>
				<view class="right">
					<text>{{usersins.userScore}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="box1">
				<text>风险评测</text>
				<view class="right">
					<text>{{usersins.userAssessmentLevel}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="box1">
				<text>更多</text>
				<view class="right" @click="go">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-top-tips ref="uTipss"></u-top-tips>
		<u-toast ref="uToast" />
		<u-toast ref="uToastss" />
	</view>
</template>

<script>
	import {
		createNamespacedHelpers
	} from "vuex";
	const {
		mapActions
	} = createNamespacedHelpers("user");
	export default {
	  async	created() {
			this.getUserinfo()
			
			//上传图片获取token
			const usertoken=uni.getStorageSync("token")
			this.token.token=usertoken
		},
		data() {
			return {
				usersins:{},//用户信息
				token: {
					"token": ""
				},//用户修改头像地址
			 action: 'http://hdannn.vaiwan.com/user/user-info/userChangePicture', // 用户修改头像地址
			}
		},
		methods: {
			...mapActions(['allUserinfo']),
			//获取用户信息
		   async getUserinfo(){
				const data= await this.allUserinfo()
				console.log("xiu",data)
				if(data.code==10001){
					this.usersins=data.data
				}else{
					console.log("获取用户失败")
				}
			},
			go(){
				uni.navigateTo({
					url:"/pages/putadress/putadress"
				})
			},
			//头像修改上传成功
		 onSuccess(data, index, lists) {
				console.log("scucc", data)
				if(data.code==10001){
					// this.$refs.uTips.show({
					// 				title: '头像修改成功',
					// 				type: 'success',
					// 				duration: '2300'
					// 			})
					this.$refs.uToast.show({
										title: '头像修改成功',
										type: 'success',
										
									})
								this.getstatuo()
				}else{
					// this.$refs.uTipss.show({
					// 	title: '头像修改失败',
					// 	type:"error"
					// });
					this.$refs.uToastss.show({
										title: '头像修改失败',
										type: 'error',	
									})
				}
			},
			// 返回之前的页面重新获取未读消息的数
			getstatuo(){
				
				 let pages = getCurrentPages(); // 当前页面
				 let beforePage = pages[pages.length - 2]; // 前一个页面
				 beforePage.onLoad(); // 执行前一个页面的onLoad方法
			},
			//下拉刷新
			onPullDownRefresh() {
				console.log('refresh');
				this.getUserinfo()
				// setTimeout(function () {
				//     uni.stopPullDownRefresh();
				// }, 1000);
				// this.getnewsShow();
				// this.getcaijinnews();
				// // this.getUserData();
				// this.userDetail();
				setTimeout(function() {
					uni.stopPullDownRefresh(); //停止下拉刷新动画
				}, 1000);
			}
		}
	}
</script>

<style lang="scss" scoped>
.box{
	background-color: #fafafa;
	height: 100vh;
	.cnter{
		padding: 10rpx 20rpx;
		background-color: #ffffff;
		//border: 1px solid red;
		font-size: 30rpx;
		font-weight: 500;
		.box1{
			padding: 20rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.right{
				color: #d8d8d8;
				display: flex;
				image{
					border: 1px solid black;
					width: 120rpx;
					height: 120rpx;
					border-radius: 10rpx;
				}
			}
			border-bottom: 1px solid #fafafa;
		}
	}
}
</style>
